<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>企业信息完善</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
</head>
<body>
<div>
    <div class="header_line">
        当前位置：企业信息管理<span>&gt;</span><strong>企业信息</strong>
    </div>
    <div class="mt10"></div>
    <form id="form_data" action="${basePath}/enterprise/updateEnterpriseInfo" enctype="multipart/form-data"
          method="post">
        <table class="table_detail">
            <tr class="tr_header">
                <td colspan="2">&nbsp;&nbsp;企业信息</td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>联系人</label></td>
                <td class="width70p"><input name="contact" value="${enterPriseInfo.contact}" placeholder="请输入联系人"/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>联系电话</label></td>
                <td class="width70p"><input name="phone" value="${enterPriseInfo.phone}" placeholder="请输入联系电话"/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>企业名称</label></td>
                <td class="width70p"><input name="name" value="${enterPriseInfo.name}" placeholder="请输入企业名称"/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>公司地址</label></td>
                <td class="width70p"><input name="address" value="${enterPriseInfo.address}" placeholder="请输入公司地址"/>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>组织机构代码</label></td>
                <td class="width70p"><input name="organizationId" value="${enterPriseInfo.organizationId}" style="background-color: #f0f0f0"
                                            placeholder="请输入组织机构代码" readonly/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>营业执照注册号</label></td>
                <td class="width70p"><input name="businessId" value="${enterPriseInfo.businessId}"
                                            placeholder="请输入营业执照注册号"/></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>税务登记号</label></td>
                <td class="width70p"><input name="taxId" value="${enterPriseInfo.taxId}" placeholder="请输入税务登记号"/></td>
            </tr>
            <tr>
                <td class="width30p"><label>企业邮箱</label></td>
                <td class="width70p"><input name="mail" value="${enterPriseInfo.mail}" placeholder="请输入企业邮箱"/></td>
            </tr>
            <tr>
                <td class="width30p"><label>邮编</label></td>
                <td class="width70p"><input name="postcode" value="${enterPriseInfo.postcode}" placeholder="请输入邮编"/>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label>海关十位编码</label></td>
                <td class="width70p"><input name="crCode" value="${enterPriseInfo.crCode}" placeholder="请输入海关十位编码"/>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label>关区代码</label></td>
                <td class="width70p"><input name="customsCode" value="${enterPriseInfo.customsCode}"
                                            placeholder="请输入关区代码"/></td>
            </tr>
            <tr>
                <td class="width30p"><label>报检登记号</label></td>
                <td class="width70p"><input name="declRegNo" value="${enterPriseInfo.declRegNo}"
                                            placeholder="请输入报检登记号"/></td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;&nbsp;请上传以下三证原件的扫描件<span
                        style="color: #acacac">支持jpg、jpeg、bmp、gif格式图片，大小不超过2M</span></td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>营业执照</label></td>
                <td class="width70p">
                    <c:if test="${empty enterPriseInfo.businessName}">
                        <input type="file" name="businessLicense"/>
                    </c:if>
                    <c:if test="${not empty enterPriseInfo.businessName}">
                        <a style="margin-left: 15px;"
                           href="${basePath}/enterprise/download?id=${enterPriseInfo.id}&type=business">${enterPriseInfo.businessName}</a>
                        <a style="margin-left: 15px;" href="javascript:void(0)"
                           onclick="deleteFile(this, 'businessLicense')">删除</a>
                    </c:if>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>税务登记证</label></td>
                <td class="width70p">
                    <c:if test="${empty enterPriseInfo.taxName}">
                        <input type="file" name="taxLicense"/>
                    </c:if>
                    <c:if test="${not empty enterPriseInfo.taxName}">
                        <a style="margin-left: 15px;"
                           href="${basePath}/enterprise/download?id=${enterPriseInfo.id}&type=tax">${enterPriseInfo.taxName}</a>
                        <a style="margin-left: 15px;" href="javascript:void(0)"
                           onclick="deleteFile(this, 'taxLicense')">删除</a>
                    </c:if>
                </td>
            </tr>
            <tr>
                <td class="width30p"><label><em>*</em>组织机构代码证</label></td>
                <td class="width70p">
                    <c:if test="${empty enterPriseInfo.organizationName}">
                        <input type="file" name="organizationLicense"/>
                    </c:if>
                    <c:if test="${not empty enterPriseInfo.organizationName}">
                        <a style="margin-left: 15px;"
                           href="${basePath}/enterprise/download?id=${enterPriseInfo.id}&type=organization">${enterPriseInfo.organizationName}</a>
                        <a style="margin-left: 15px;" href="javascript:void(0)"
                           onclick="deleteFile(this, 'organizationLicense')">删除</a>
                    </c:if>
                </td>
            </tr>
            <tr class="tr_button">
                <td colspan="2"><input type="submit" value="提交"></td>
            </tr>
        </table>
    </form>
</div>
<script>
    $(function () {
        if (${status eq 1}) {
            layer.alert("保存成功", {icon: 6})
        }
        if (${status eq 0}) {
            layer.alert("保存失败！错误原因:${errorMsg}", {icon: 5})
        }
        if (${not empty errorMsg}) {
            layer.alert("保存失败！错误原因:${errorMsg}", {icon: 5})
        }
        $("#form_data").validate({
            debug: false, //false表示验证通过后不要自动提交表单
            onkeyup: false, //表示关闭按键松开时候监听验证
            rules: {
                contact: {
                    required: true,
                    maxlength: 30
                },
                phone: {
                    required: true,
                    maxlength: 11
                },
                name: {
                    required: true,
                    maxlength: 80
                },
                address: {
                    required: true,
                    maxlength: 120
                },
                organizationId: {
                    required: true,
                    maxlength: 120
                },
                businessId: {
                    required: true,
                    maxlength: 120
                },
                taxId: {
                    required: true,
                    maxlength: 120
                },
                mail: {
                    email: true,
                    maxlength: 120
                },
                crCode: {
                    number: true,
                    rangelength: [10, 10]
                },
                customsCode: {
                    maxlength: 120
                },
                declRegNo: {
                    maxlength: 120
                },
                postcode: {
                    number: true,
                    rangelength: [6, 6]
                },
                businessLicense: {
                    required: true,
                    checkFileFormat: true
                },
                taxLicense: {
                    required: true,
                    checkFileFormat: true
                },
                organizationLicense: {
                    required: true,
                    checkFileFormat: true
                }
            },
            messages: {
                contact: {
                    required: "请输入联系人",
                    maxlength: "超过最大30个字符限制"
                },
                phone: {
                    required: "请输入联系电话",
                    maxlength: "请输入正确联系电话"
                },
                name: {
                    required: "请输入企业名称",
                    maxlength: "超过最大80个字符限制"
                },
                address: {
                    required: "请输入公司地址",
                    maxlength: "超过最大120个字符限制"
                },
                organizationId: {
                    required: "请输入组织机构代码",
                    maxlength: "超过最大120个字符限制"
                },
                businessId: {
                    required: "请输入营业执照注册号",
                    maxlength: "超过最大120个字符限制"
                },
                taxId: {
                    required: "请输入税务登记号",
                    maxlength: "超过最大120个字符限制"
                },
                mail: {
                    email: "请输入正确的邮箱",
                    maxlength: "超过最大120个字符限制"
                },
                crCode: {
                    number: "请输入正确的海关十位编码",
                    rangelength: "请输入正确的海关十位编码"
                },
                customsCode: {
                    maxlength: "超过最大120个字符限制"
                },
                declRegNo: {
                    maxlength: "超过最大120个字符限制"
                },
                postcode: {
                    number: "请输入正确的邮编",
                    rangelength: "请输入正确的邮编"
                },
                businessLicense: {
                    required: "请上传营业执照"
                },
                taxLicense: {
                    required: "请上传税务登记证"
                },
                organizationLicense: {
                    required: "请上传组织机构代码证"
                }
            },
            //验证通过可以在这里做你想做的事情
            submitHandler: function (form) {
                form.submit();
            }
        });
    });

    jQuery.validator.addMethod("checkFileFormat", function (value) {
        var allowExt = ".jpg|.jpeg|.bmp|.gif|.png|";//允许上传的文件类型 0为无限制 每个扩展名后边要加一个"|" 小写字母表示
        var fileExt = value.substr(value.lastIndexOf(".")).toLowerCase();
        if (allowExt.indexOf(fileExt + "|") == -1) {
            return false;
        }
        return true;
    }, "该文件类型不允许上传,请重新选择");

    function deleteFile(dom, name) {
        dom.parentNode.innerHTML = "<input type='file' name='" + name + "'/>";
    }
</script>
</body>
</html>
